package reference;

import bean.Student;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * 构造器引用
 * @Author: lyy
 * Date: 2021/12/23 14:34
 */
public class ConstructorTest {
	public static void main(String[] args) {
		// lambda表达式，实例化对象
		Supplier<Student> s01 = () -> new Student();
		Function<Integer, Student> f01 = (id) -> new Student(id);
		Student stu02 = f01.apply(2021);
		BiFunction<Integer, String, Student> bf01 = (id, name) -> new Student(id, name);
		Student stu03 = bf01.apply(2022, "yy");
		System.out.println("s01：" + s01.get());
		System.out.println("s02：" + stu02);
		System.out.println("s03：" + stu03);
		// 方法引用，等价写法
		Supplier<Student> s02 = Student::new;
		Function<Integer, Student> f02 = Student::new;
		Student stu05 = f02.apply(20);
		BiFunction<Integer, String, Student> bf02 = Student::new;
		Student stu06 = bf02.apply(21, "waiwai");
		System.out.println("s04：" + s02.get());
		System.out.println("s05：" + stu05);
		System.out.println("s06：" + stu06);
	}
}
